package com.itheima04;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/7/16
 */
public class ForDemo {
    /**
     *      增强for循环
     */
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        for (int i : arr) {
            System.out.println(i);
        }
        System.out.println("--------");
        String[] str = {"hello","world","Java"};
        for (String s : str) {
            System.out.println(s);
        }
        System.out.println("--------");
        List<String> list = new ArrayList<>();
        list.add("世界");
        list.add("你好");
        list.add("！！！");
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("---------");
        //增强for循环内部原理是一个Iterator迭代器
        /*for (String s : list) {
            if (s.equals("你好")) {
                list.add("我爱Java");     //ConcurrentModificationException
            }
            System.out.println(list);
        }*/
    }
}
